package org.flint92.springboot.web.client;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.flint92.springboot.web.model.User;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author flint92
 */
public class RestClient {

    /**
     * mac need close firewall
     */
    public static void main(String[] args) {

        HttpClientBuilder builder = HttpClientBuilder.create();

        HttpClient httpClient = builder.build();

        ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);

        RestTemplate restTemplate = new RestTemplate(factory);

//        RestTemplate restTemplate = new RestTemplate();

        ResponseEntity<User> response = restTemplate.getForEntity("http://127.0.0.1:9001/web/xml/user", User.class);

        System.out.println(response.getBody());
    }

}
